#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@Author   : 李吉凯
@Email    : lijikai1206@163.com
@Time     : 2021/7/12 20:44
@File     : knowledgeType.yaml.py
'''
from service.FeishuApi.baseRequest.BaseFeishu import BaseFeishu

class KnowledgeType(BaseFeishu):
    def __init__(self):
        BaseFeishu.__init__(self)
        self.header = {
            'Authorization': f'Bearer {self.token}',
            'Content-Type': 'application/json; charset=utf-8',
            'Header Key': 'X-Lark-Helpdesk-Authorization',
            'Header Value': self.res02
        }

    def create_knowleadge_type(self, name, parent_id, language):
        # url = 'https://open.feishu.cn/open-apis/helpdesk/v1/faqs'
        url = 'https://open.feishu.cn/open-apis/helpdesk/v1/categories'
        params = {
            "name": name,
            "parent_id": parent_id,
            "language": language
        }
        res = self.kl_req.post(url, data=params, headers=self.header)
        print('res:', res)
        print('res_Text', res.json())
        return res

    def get_knowledge_list(self, parent_id):
        url = f'https://open.feishu.cn/open-apis/helpdesk/v1/categories/{parent_id}'
        res = self.kl_req.get(url, headers=self.header)
        return res

    def get_all_knowledge_list(self, order_by, asc):
        url = f'https://open.feishu.cn/open-apis/helpdesk/v1/categories'
        data = {
            'lang': 'zh_cn',
            'order_by': order_by,
            'asc': asc
        }
        res = self.kl_req.get(url, data=data, headers=self.header)
        return res

    def update_knowledge_type(self, name, parent_id):
        url = f'https://open.feishu.cn/open-apis/helpdesk/v1/categories/{parent_id}'
        params = {
            "name": name,
            "parent_id": parent_id
        }
        res = self.kl_req.patch(url, data=params, headers=self.header)
        return res

    def delete_knowledge_type(self, parent_id):
        url = f'https://open.feishu.cn/open-apis/helpdesk/v1/categories/{parent_id}'
        res = self.kl_req.delete(url, headers=self.header)
        return res

